import request from './request'
import rap2 from './mock'

/**
 * 获取所有用户数据
 */
export const getUsers = () => request({
  url: '/users',
  method: 'get'
})

/**
 * 修改用户数据
 */
export const modifyUser = userinfo => request({
  url: '/users/' + userinfo.id,
  method: 'put',
  data: userinfo
})

/**
 * 删除用户信息
 * @param {*} userinfo 
 */
export const deleteUser = userinfo => request({
  url: '/users/' + userinfo.id,
  method: 'delete'
})

/**
 * 添加用户信息
 * @param {*} userinfo 
 */
export const addUser = userinfo => request({
  url: '/users',
  method: 'post',
  data: userinfo
})

/**
 * 用户登录
 * @param {*} param0 
 */
export const login = ({username, password}) => rap2({
  url: '/api/v1/sessions',
  method: 'post',
  data: {
    username,
    password
  }
})

/**
 * 用户退出
 * @param {*} username 
 */
export const logout = username => rap2({
  url: '/api/v1/sessions/' + username,
  method: 'delete'
})
